package com.bstek.urule.console.servlet.console;

import com.bstek.urule.console.servlet.base.BaseController;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *
 * </p>
 *
 * @author zhouchaoliang
 * @since 2021/12/9
 */
@Controller
public class ConsoleController extends BaseController {
    @Autowired
    private DebugMessageHolder debugMessageHolder;

    @GetMapping("/urule/console")
    public ModelAndView console(HttpServletRequest req, HttpServletResponse resp) {
        String key=req.getParameter("key");
        String msg=null;
        if(StringUtils.isBlank(key)){
            msg="<h2 style='color:red'>请指定要查看的调试消息的key值</h2>";
        }else{
            msg=debugMessageHolder.getDebugMessage(key);
        }
        ModelAndView mv = new ModelAndView("/console");
        mv.addObject("title", "URule Console");
        mv.addObject("msg", msg);
        return mv;
    }
}
